package net.lab1024.sa.admin.module.business.place.controller;

import net.lab1024.sa.admin.module.business.place.domain.form.PlaceAddForm;
import net.lab1024.sa.admin.module.business.place.domain.form.PlaceQueryForm;
import net.lab1024.sa.admin.module.business.place.domain.form.PlaceUpdateForm;
import net.lab1024.sa.admin.module.business.place.domain.vo.PlaceVO;
import net.lab1024.sa.admin.module.business.school.domain.form.RSchoolAddForm;
import net.lab1024.sa.admin.module.business.school.domain.form.RSchoolQueryForm;
import net.lab1024.sa.admin.module.business.school.domain.form.RSchoolUpdateForm;
import net.lab1024.sa.admin.module.business.school.domain.vo.RSchoolVO;
import net.lab1024.sa.admin.module.business.place.service.RSchoolService;
import net.lab1024.sa.admin.module.system.type.domain.TypeVO;
import net.lab1024.sa.base.common.domain.ValidateList;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
 * 学校信息 Controller
 *
 * @Author syf
 * @Date 2025-05-14 10:36:40
 * @Copyright 畅想科技
 */

@RestController
@Tag(name = "")
public class RSchoolController {

    @Resource
    private RSchoolService rSchoolService;

    @Operation(summary = "分页查询 @author syf")
    @PostMapping("/rSchool/queryPage")
    public ResponseDTO<PageResult<PlaceVO>> queryPage(@RequestBody @Valid PlaceQueryForm queryForm) {
        return ResponseDTO.ok(rSchoolService.queryPage(queryForm));
    }
    @Operation(summary = "分页查询 @author syf")
    @PostMapping("/rSchool/queryType")
    public ResponseDTO<List<TypeVO>> queryType(@RequestBody @Valid PlaceQueryForm queryForm) {
        PageResult<PlaceVO> placeVOList = rSchoolService.queryPage(queryForm);
        List<PlaceVO> rSchoolVOList = placeVOList.getList();
        List<TypeVO> typeVOList = new ArrayList<>();
        for (PlaceVO rSchoolVO : rSchoolVOList) {
            TypeVO typeVO = new TypeVO();
            typeVO.setValue(rSchoolVO.getPlaceId());
            typeVO.setText(rSchoolVO.getPlaceName());
            typeVOList.add(typeVO);
        }
        return ResponseDTO.ok(typeVOList);
    }
    @Operation(summary = "分页查询 @author syf")
    @PostMapping("/rSchool/querySchoolPage")
    public ResponseDTO<PageResult<PlaceVO>> querySchoolPage() {
        PlaceQueryForm queryForm = new PlaceQueryForm();
        queryForm.setPageNum(1L);
        queryForm.setPageSize(100000L);
        return ResponseDTO.ok(rSchoolService.queryPage(queryForm));
    }
    @Operation(summary = "添加 @author syf")
    @PostMapping("/rSchool/add")
    public ResponseDTO<String> add(@RequestBody @Valid PlaceAddForm addForm) {
        return rSchoolService.add(addForm);
    }

    @Operation(summary = "更新 @author syf")
    @PostMapping("/rSchool/update")
    public ResponseDTO<String> update(@RequestBody @Valid PlaceUpdateForm updateForm) {
        return rSchoolService.update(updateForm);
    }

    @Operation(summary = "批量删除 @author syf")
    @PostMapping("/rSchool/batchDelete")
    public ResponseDTO<String> batchDelete(@RequestBody ValidateList<Long> idList) {
        return rSchoolService.batchDelete(idList);
    }

    @Operation(summary = "单个删除 @author syf")
    @GetMapping("/rSchool/delete/{schoolId}")
    public ResponseDTO<String> batchDelete(@PathVariable Long schoolId) {
        return rSchoolService.delete(schoolId);
    }
}
